<!--
 * @Author: doing
 * @Date: 2023-08-22 11:38:46
 * @LastEditors: git config user.name && git config user.email
 * @LastEditTime: 2023-08-22 19:16:24
 * @FilePath: \项目\src\components\FormDialog.vue
 * @Description: 
 * 对话框组件
 * Copyright (c) 2023 by 1540265624@qq.com, All Rights Reserved. 
-->

<template>
    <el-dialog v-model="showDialog" 
    :title="title" 
    :close-on-click-modal="true" 
    :destroy-on-close="destroyOnClose"
    @close="clean"
    >
        <div class="formDrawer">
            <slot></slot>
            <div class="actions">
                <el-button type="primary" @click="submit" :loading="loading">{{ confirmText }}</el-button>
                <el-button type="default" @click="close">取消</el-button>
            </div>
        </div>
    </el-dialog>
</template>
<script setup>
import { ref } from "vue"

const showDialog = ref(false)

const props = defineProps({
    title: String,
    size: {
        type: String,
        default: "45%"
    },
    destroyOnClose: {
        type: Boolean,
        default: false
    },
    confirmText: {
        type: String,
        default: "提交"
    }
})

const loading = ref(false)
const showLoading = () => loading.value = true
const hideLoading = () => loading.value = false

// 打开
const open = () => showDialog.value = true

// 关闭
const close = () => showDialog.value = false

// 提交
const emit = defineEmits(["submit","clean"])
const submit = () => emit("submit")
const clean = () => emit("clean")

//清除表单

// 向父组件暴露以下方法
defineExpose({
    open,
    close,
    showLoading,
    hideLoading
})

</script>
<style>
.formDrawer {
    width: 100%;
    height: 100%;
    position: relative;
    @apply flex flex-col;
}

.formDrawer .body {
    flex: 1;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 50px;
    overflow-y: auto;
}

.formDrawer .actions {
    height: 50px;
    @apply mt-auto flex items-center;
}
</style>
